//
//  UIImageView_extesion.m
//  BDD_TWO
//
//  Created by WangZhenyu on 2018/11/21.
//  Copyright © 2018 WangZhenyu. All rights reserved.
//

#import "UIImageView_extesion.h"
#import "AppDelegate.h"
#import "MIPhotoBrowser.h"

@interface UIImageView()<MIPhotoBrowserDelegate>{
}
@end

@implementation UIImageView (extension)

- (void)addGestureEnlargeHandle{
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapRecognize = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stepTapAction:)];
    tapRecognize.numberOfTapsRequired = 1;
    [self addGestureRecognizer:tapRecognize];
}

- (void)setPersonId:(NSString *)peopleId{
    self.tag = [peopleId integerValue] + 1000;
}


- (void)stepTapAction:(UIGestureRecognizer *)gesture{
    [self setBackgroundColor:[UIColor clearColor]];
    MIPhotoBrowser *photoBrowser = [[MIPhotoBrowser alloc] init];
    photoBrowser.delegate = self;
    photoBrowser.currentImgae = [self getImageFromView:self];
    photoBrowser.imageCount = 1;
    photoBrowser.currentImageIndex = 0;
    [photoBrowser show];
    
    [self setBackgroundColor:[UIColor whiteColor]];
}

- (UIImage *)photoBrowser:(MIPhotoBrowser *)photoBrowser placeholderImageForIndex:(NSInteger)index{
    return [self getImageFromView:self];
}

- (void)photoBrowserColse {
    
}

- (UIImage *)getImageFromView:(UIView *)view {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
@end
